using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Castle.Core;
using NUnit.Framework;

namespace DeclarativeTest.Tests
{
	public static class TestUtils
	{
		public static void AreEqual<K,V>( this IDictionary<K,V> dictionary, params KeyValuePair<K,V>[] expectedEntries )
		{
			CollectionAssert.AreEqual(
				expectedEntries.OrderBy( pair => pair.Key ).ToArray(),
				dictionary.OrderBy( pair => pair.Key ).ToArray()
				 );
		}

		public static void AreEqual<K,V>( this IDictionary dictionary, params DictionaryEntry[] expectedEntries )
		{
			Dictionary<K,V> typedDictionary = new Dictionary<K,V>();
			dictionary.Cast<DictionaryEntry>().ForEach( entry => typedDictionary.Add( (K)entry.Key, (V)entry.Value ) );
			
			List<KeyValuePair<K,V>> typedEntries = new List<KeyValuePair<K,V>>();
			foreach ( DictionaryEntry entry in expectedEntries ){
				typedEntries.Add( new KeyValuePair<K,V>((K)entry.Key, (V)entry.Value) );
			}

			AreEqual( typedDictionary, typedEntries.ToArray() );
		}

	}
}